Ext.onReady(function() {
	var checkPanel=Ext.create('Ext.panel.Panel', {
		region : 'south',
	    title: '审批详情',
	    height:'80%',
	    html: '<iframe src="'+requestUrl+'" width="100%" height="100%"></iframe>',
	});
	
	var gridStore = Ext.create('Ext.data.Store', {
	    fields: ["taskName","taskUserName","taskCheckStatus", "startDate", "endDate"],
	    //是否在服务端排序 （true的话，在客户端就不能排序）
	    remoteSort: false,
	    proxy: {
	        type: 'ajax',
	        url: contextPath+'/processComponent/queryHistoricActivity',
	        reader: {   //这里的reader为数据存储组织的地方，下面的配置是为json格式的数据，例如：[{"total":50,"rows":[{"a":"3","b":"4"}]}]
	            type: 'json', //返回数据类型为json格式
	            root: 'obj',  //数据
	            totalProperty: 'total' //数据总条数
	        },
	        extraParams:{
	        	processInstanceId:processInstanceId
	        }
	    }
	});
	gridStore.load();
	var columns = [{
		text : "任务名称",
		dataIndex : 'taskName',
		width:'20%'
	}, {
		text : "参与人员",
		dataIndex : 'taskUserName',
		width:'20%'
	}, {
		text : "状态",
		dataIndex : 'taskCheckStatus',
		width:'20%'
	}, {
		text : "开始时间",
		dataIndex : 'startDate',
		width:'20%',
		renderer : function(val) {
			if(val){
				return Ext.Date.format(new Date(val),'Y-m-d H:i:s')
			}
			return "";
		}
	}, {
		text : "结束时间",
		dataIndex : 'endDate',
		width:'20%',
		renderer : function(val) {
			if(val){
				return Ext.Date.format(new Date(val),'Y-m-d H:i:s')
			}
			return "";
		}
	}];
	var grid=Ext.create('Ext.grid.Panel', {
		region : 'center',
		title:"审批历史",
		height:'20%',
		store : gridStore,
		columns : columns
	});
	//审核窗口
	
	Ext.create('Ext.panel.Panel', {
		buttonAlign:'center',
	    title: '审批',
	    height:'100%',
	    layout:'border',
	    items:[grid,checkPanel],
	    tbar:[{
	    	 xtype: "button", text: "审核",iconCls:'icon-accept',handler:checkPass
	    }],
	    renderTo: Ext.getBody()
	});
	var checkWindow;
	function checkPass(){
		if(!checkWindow){
			checkWindow=Ext.create('Ext.window.Window',{
				title:'审核',
				width : 400,
				height : 200,
                closable: true,
                modal : true, 
                closeAction: 'hide',
                buttonAlign:'center',
                items:[{
		            xtype: "container",
		            //layout: "fit",
		            anchor: '80%',
		            items: [
		                {
		                    xtype: 'radiogroup',
		                    fieldLabel: '审核状态',
		                    width:300,
		                    id:"checkStatus",
		                    items: [
		                        {boxLabel: '通过', name: 'checkStatus', checked: true,inputValue:'0'},
		                        {boxLabel: '不通过', name: 'checkStatus',inputValue:'1'}
		                    ]
		                
		            }]},{
		            xtype: "container",
		            layout: "fit",
		            anchor: '80%',
		            items: [
		                {
		                	xtype: 'textarea',
		                	width:300,
		                    name:'message',
		                    id:"message",
		                    fieldLabel:'审批意见:'
                        }
		            ]}
                ],
                buttons: [
                          { text: '提交',iconCls:'icon-accept',handler:processPass,id:"processCommitBtn"}
                        ]
			});
			checkWindow.show();
		}else{
			checkWindow.show();
		}
		
	}

	function processPass(){
		var message=Ext.getCmp("message").getValue();
		var checkStatus=Ext.getCmp('checkStatus').getChecked()[0].inputValue;
		Ext.getCmp("processCommitBtn").setVisible(false);
		Ext.Msg.wait("正在处理，请稍等...","");
		Ext.Ajax.request({
			timeout: 300000,
			url: contextPath+'/processComponent/processPass',
			params:{
				message:message,
				checkStatus:checkStatus,
				taskId:taskId
			},
			callback: function (options, success, response) {
				 Ext.Msg.hide();
				 if (success) {
					 var obj = JSON.parse(response.responseText);
					 if(obj.res=="1"){
						 Ext.MessageBox.confirm("提示","审核成功,是否关闭当前页面?",function(btn,txt){
							 if(btn=="yes"){
								 checkWindow.hide();
								 window.close();
							 }
						 });
						  
					 }else{
						 Ext.getCmp("processCommitBtn").setVisible(true);
						 Ext.MessageBox.alert("系统提示",obj.resMsg); 
					 }
	        	 }else{
	        		 Ext.getCmp("processCommitBtn").setVisible(true);
	        		 Ext.MessageBox.alert("系统提示","系统异常!");
	        	 }
			}
			
		});
	}
	
});